package com.qk.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.entity.Activity;
import com.qk.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 活动管理控制器
 */
@RestController
@RequestMapping("/activities")
public class ActivityController {

    @Autowired
    private ActivityService activityService;

    /**
     * 新增活动
     */
    @PostMapping
    public Result addActivity(@RequestBody Activity activity) {
        activityService.addActivity(activity);
        return Result.success();
    }

    /**
     * 根据ID查询活动信息
     */
    @GetMapping("/{id}")
    public Result getActivityById(@PathVariable("id") Integer id) {
        Activity activity = activityService.getActivityById(id);
        return Result.success(activity);
    }

    /**
     * 条件分页查询活动列表
     */
    @GetMapping
    public Result list(Integer channel,Integer type,Integer status,
                       @RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int pageSize) {
        PageResult<Activity> activityPage = activityService.list(channel, type, status, page, pageSize);
        return Result.success(activityPage);
    }

    /**
     * 更新活动信息
     */
    @PutMapping
    public Result updateActivity(@RequestBody Activity activity) {
        activityService.updateActivity(activity);
        return Result.success();
    }

    /**
     * 删除活动
     */
    @DeleteMapping("/{id}")
    public Result deleteActivity(@PathVariable Integer id) {
        activityService.deleteActivity(id);
        return Result.success();
    }

    /**
     * 根据活动类型查询活动列表
     */
    @GetMapping("/type/{type}")
    public Result getActivitiesByType(@PathVariable Integer type) {
        List<Activity> activityList = activityService.getActivitiesByType(type);
        return Result.success(activityList);
    }

}